package com.hhh.petadopt.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhh.petadopt.mapper.NewsMapper;
import com.hhh.petadopt.pojo.News;
import com.hhh.petadopt.service.NewsService;
/**
 * 新闻咨询页面
 * @author 杜镇声声
 *
 */
@Service
public class NewsServiceImpl implements NewsService {
	
	@Autowired
	private NewsMapper newsMapper;

	//查询前五十条新闻
	@Override
	public List<News> selectNews() {
		List<News> newss = newsMapper.selectNewsList();
		//将时间转换为yyyy-mm-dd格式
		List<News> newsList = new ArrayList<News>();
		for (News news : newss) {
			news.setCreated(news.getCreated().substring(0, 10));
			newsList.add(news);
		}
		return newsList;
	}

	//查询新闻详情
	@Override
	public News selectNewsInfo(Integer id) {
		News news = newsMapper.selectNewsInfoById(id);
		//将时间转换为yyyy-mm-dd格式
		news.setCreated(news.getCreated().substring(0, 10));
		return news;
	}

}
